package TestClass;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/ajax2")
public class ajax2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //接受前端传过来的姓名和密码
        String name = req.getParameter("name");
        String key = req.getParameter("key");
        //把值传回到前端 返回前端普通字符串
        PrintWriter writer =resp.getWriter();
        writer.write("我是来自后端的用户："+name);
        writer.write("我是来自后端的密码："+key);
    }
}
